<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.milk.entity.Members" %>
<html>
<head>
    <title>会员管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/member_management.css">
</head>
<body>
<div class="container">
    <h2>会员管理</h2>

    <!-- 添加、返回、查询所有和查询功能放在一行 -->
    <div class="actions-row">
        <a href="${pageContext.request.contextPath}/members/add" class="action-button">添加会员</a>
        <a href="javascript:history.back()" class="action-button return-button">返回上一页</a>
        <a href="${pageContext.request.contextPath}/members" class="action-button query-all-button">查询所有</a>
        <form action="${pageContext.request.contextPath}/members/search" method="get" class="search-form">
            <input type="text" id="searchUserName" name="searchUserName" placeholder="请输入会员用户名">
            <input type="submit" value="搜索" class="search-button">
        </form>
    </div>

    <!-- 显示所有会员信息 -->
    <table class="member-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>电话号码</th>
            <th>积分</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            List<Members> members = (List<Members>) request.getAttribute("members");
            if (members != null) {
                for (Members member : members) {
        %>
        <tr>
            <td><%=member.getId()%></td>
            <td><%=member.getUserName()%></td>
            <td><%=member.getPhoneNumber()%></td>
            <td><%=member.getPoints()%></td>
            <td>
                <a href="${pageContext.request.contextPath}/members/edit?id=<%=member.getId()%>" class="action-link">编辑</a>
                <a href="${pageContext.request.contextPath}/members/delete?id=<%=member.getId()%>" class="action-link">删除</a>
            </td>
        </tr>
        <%
                }
            }
        %>
        </tbody>
    </table>
</div>

<!-- 引入 JavaScript 文件 -->
<script src="${pageContext.request.contextPath}/js/member_management.js"></script>
</body>
</html>